home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / ScriptServer 1.0a4 / SSCompile < prev    next >
Encoding:
Text File  |  1994-08-20  |  2.6 KB  |  104 lines  |  [TEXT/MPS ]

  1. #    SSCompile
  2. #
  3. #    This uses the SendAE tool and the ScriptServer application to 
  4. #    compile text files into AppleScripts.
  5. #
  6. #    Written by Ult Mundane & Jon Pugh
  7. #
  8. #    Option -c: Preprocess with C compiler first.
  9. #    Option -e: Preprocess with UltScript compiler first.
  10. #    Option -p: Preprocess only; don't compile with AppleScript
  11. #    Option -s: Launch ScriptServer before trying to send Apple events to it
  12. #
  13. #    {1} is the file to compile
  14. #    {2} is the output script file
  15.  
  16. Unset lSource
  17. Unset lTarget
  18.  
  19. Loop
  20.     If "{1}" == ""
  21.         Break
  22.     Else If "{1}" == "-c"
  23.         Set lPreprocessC TRUE
  24.     Else If "{1}" == "-e"
  25.         Set lPreprocessUltScript TRUE
  26.     Else If "{1}" == "-s"
  27.         Set lLaunchScriptServer TRUE
  28.     Else If "{1}" == "-p"
  29.         Set lPreprocessOnly TRUE
  30.     Else If "{lSource}" == ""
  31.         Set lSource "{1}"
  32.         Set lOrigSource "{lSource}"
  33.     Else If "{lTarget}" == ""
  34.         Set lTarget "{1}"
  35.     Else
  36.          Echo "### SSCompile - Too many parameters"
  37.         Exit
  38.     End
  39.     Shift
  40. End
  41.  
  42. If "{lTarget}" == ""
  43.     Set lPreprocessOnly TRUE
  44. End
  45.  
  46. If {lPreprocessC} == TRUE || {lPreprocessUltScript} == TRUE
  47.     If {lPreprocessC} == TRUE
  48.         C -e2 "{lSource}" > "{TempFolder}"Temp
  49.         # Strip compiler comments
  50.         StreamEdit "{TempFolder}"Temp -e '/•[∂#]/ Delete' -o "{TempFolder}"Temp
  51.     Else
  52.         Catenate "{lSource}" > "{TempFolder}"Temp
  53.     End
  54.     
  55.     If {lPreprocessUltScript} == TRUE
  56.         # I tried using StreamEdit to strip the blank lines at the
  57.         # beginning of the file, but it always seems to insert one blank line.
  58.         Target "{TempFolder}"Temp
  59.         SizeWindow 20 20 "{TempFolder}"Temp
  60.         
  61.         # Don't exit just because a Find/Replace failed
  62.         Set lStartExit {Exit}
  63.         Set Exit 0
  64.     
  65.         # Replace "#include <file>" with the contents of <file>
  66.         Find • "{TempFolder}"Temp
  67.         Loop
  68.             Find /∂#include [∂"∂<](≈)®1[∂"∂>]∂n/ "{TempFolder}"Temp
  69.             Break If {Status} != 0
  70.             Set lInclude "`Catenate "{TempFolder}"Temp.§`"
  71.             Continue If "{lInclude}" !~ /∂#include [∂"∂<]«0,1»(≈)®1[∂"∂>]«0,1»/
  72.             Catenate `WhereIs "{®1}" -s "{gProjectDir}"` > "{TempFolder}"Temp.§
  73.         End
  74.     
  75.         # Remove all c style comments (/* comment */)
  76.         Find • "{TempFolder}"Temp
  77.         Replace -c ∞ /[ ∂t]*∂/∂*/:/∂*∂/[∂n ∂t]«0,1»/ "" "{TempFolder}"Temp
  78.         Set Exit {lStartExit}
  79.         Close -y "{TempFolder}"Temp
  80.     End
  81.     
  82.     Set lSource "{TempFolder}"Temp
  83. End
  84.  
  85. If {lLaunchScriptServer} == TRUE
  86.     ScriptServer
  87. End
  88.  
  89. If {lPreprocessOnly} == TRUE
  90.     If "{lTarget}" == ""
  91.         Catenate "{lSource}" >> "{Worksheet}"
  92.     Else
  93.         Catenate "{lSource}" > "{lTarget}"
  94.     End
  95. Else
  96.     If "`Exists -q "{lTarget}"`"
  97.         Move -y "{lTarget}" "{TempFolder}"
  98.     End
  99.     sendAE -e JonSCmpl -t ScriptServer -timeout 18000 -----alis "{lSource}" -"to  TEXT" "{lTarget}"
  100.     If !"`Exists -q "{lTarget}"`"
  101.         Echo "### SSCompile - Error compiling ∂"{lOrigSource}∂"."
  102.     End
  103. End
  104.